home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 9
/
The PC-SIG Library on CD ROM - Ninth Edition.iso
/
1601_700
/
DISK1665
/
DISK1665.ZIP
/
LANGTPAS.KED
< prev
Wrap
Text File
|
1980-01-01
|
33KB
|
689 lines
.Notice - Last Update:1988/11/19 17:30
Importance Notice: The information contained in this option are for quick
reference only. The accuracy of it should be based on your
language reference manual.
Set Up By : Kuang H. Tseng
Language : TURBO PASCAL(R) 5.0 by BORLAND INTERNATIONAL INC.
. 1. Language Elements
Character Set
A to Z,a to z, _(underscore),0 to 9,
+ - * / = < > [ ] . , ( ) : ; ^ @ { } $ #
Data Types - (refer to separate key line for more)
Identifiers - (refer to separate key line for more)
Constants - (refer to separate key line for more)
Reserved Words (refer to separate key line for more)
Operators and the precedence - (refer to separate key line for more)
Delimiters - blank,end of line mark,a comment
Program Line - maximum length 126
Comments - '{' and '}' or '(*' and '*)'
Units - (refer to separate key line for more)
Statements - (refer to separate key line for more)
Procedures - (refer to separate key line for more)
Functions - (refer to separate key line for more)
File Types
Compiler Directives - (refer to separate key line for more)
. 2. Data Types
integer - 2 bytes, signed -32768 to 32767
shortint - 1 byte, signed -128 to 127
longint - 4 bytes, signed -2147483648 to 2147483647
byte - 1 byte, unsigned 0 to 255, subrange of type Integer
word - 2 bytes, unsigned 0 to 65535
real - 6 bytes, 2.9E-39 to 1.7E+38 with mantissa 11-12 digits
single - 4 bytes, 1.5E-45 to 3.4E+38 with mantissa 7-8 digits
double - 8 bytes, 5.0E-324 to 1.7E+308 with mantissa 15-16 digits
extended - 10 bytes, 3.4E-4932 to 1.1E+4932 with mantissa 19-20 digits
comp - 8 bytes, -2**63+1 to 2**63-1 with mantissa 19-20 digits
boolean - 1 byte, True or False
char - 1 byte, one character in ASCII character set
string - the defined length plus one byte
array - consist of a fixed number of components which are all same type
pointer - a varable containing the memory address of another variable
record - consist of a fixed number of fields which may be different types
set - a collection of related objects
. 3.1 Identifiers
- denote labels, constants, types, variables, procedure, function, units,
programs, and fields in records
- consists of a letter or underscore followed by letters,digits,underscords
- any length but only 63 characters are significant
- not case sensitive
- unit identifier may need to qualify the same identifiers
. 3.2 Constants
- decimal integer : range -32768 to 32767
- hexadecimal integer :preceded by a dollar sign $, range $0000 to $FFFF
- string : sequence of characters enclosed in single quotes
- ASCII : preceded by symbol #
- control character : preceded by symbol ^
. 3.3 Reserved Words
absolute and array
begin
case const
div do downto
else end external
file forward function
goto
if implementation in inline interface
interrupt
label
mod
nil not
of or
packed procedure program
record repeat
set shl shr string
then to type
unit until uses
var
while with
xor
. 4. Operators and the Precedence
Unary @ not
Arithmetic *,/,div,mod,and shl,shr,+,-,or,xor
Relational =,<>,<,>,<=,=>,in
Assignment :=
. 5.1 Units
- Unit is a library or collection of constants,data types,variables,
procedures and functions. It is used to split large program into modulars.
- Source code is written as .PAS file and can be precompiled into .TPU file
- The structure of unit is as following:
UNIT <identification>
INTERFACE
USES <list of other units>; {optional}
{ public declarations }
IMPLEMENTATION
USES <list of other units>; {optional}
{ private declarations }
{ implementation of procedures and functions }
BEGIB
{ initialization code }
END.
- 8 standard precompiled units provided standard procedures and functions in
System - run-time library
Overlay - overlay manager
Graph - support CGA,EGA,VGA,HERC,3270PC,MCGA,AT&T6300 graphics
Dos - date,time,directory and program execution
Crt - display,keyboard,color,window and sound
Printer - printer access
Turbo3 - provide compatibility with Turbo Pascal 3.0
Graph3 - Turbo Pascal 3.0 Turtlegraphics
. 5.2 List of Statements
assignment ,i.e., A := 10;
CASE...OF...ELSE...END
FOR...TO/DOWNTO...DO
GOTO
IF...THEN..ELSE
PROCEDURE ,i.e., readfile(key,rcd);
REPEAT...UNTIL
WHILE varname DO BEGIN ... END
WITH...DO
. 5.3 List of Standard Procedures & Functions() by Category
- I/O for general
Assign ChDir Close Erase GetDir MkDir Rename
Reset Rewrite RmDir Eof() IOResult()
- I/O for Text Files
Append Flush Read Readln SetTextBuf Write
Writeln Eoln() SeekEof() SeekEoln()
- I/O for Untyped Files
BlockRead BlockWrite FilePos() FileSize() Seek Truncate
- Flow Control
Exit Halt RunError
- Dynamic Allocation
Dispose FreeMem Mark New Release MaxAvail()
MemAvail()
- Transfer
Chr() FillChar Move Ord() Round() Swap()
UpCase()
- Arithmetic
Abs() ArcTan() Cos() Exp() Frac() Int()
Ln() Pi() Sin() Sqr() Sqrt()
- Ordinal
Dec Inc Odd() Pred() Succ()
- String
Delete Insert Str Val Concat() Copy()
Length() Pos()
- Pointer & Address
Addr() CSeg() DSeg() Ofs() Ptr() Seg()
SPtr() SSeg()
- Interrupt Support
GetIntVec Intr MsDos SetIntVec
- Date and Time
GetDate GetFTime GetTime PackTime SetDate SetFTime
SetTime UnpackTime
- Disk Status
DiskFree() DiskSize()
- File-Handling
FindFirst FindNext GetFAttr SetFAttr FSplit FExpand()
FSearch()
- Display-Handling
AssignCrt ClrEol ClrScr DelLine GotoXY HighVideo
InsLine LowVideo NormVideo TextBackground TextColor
TextMode Window WhereX() WhereY()
- Keyboard
KeyPressed() ReadKey()
- Graph
Arc Bar Bar3D Circle ClearDevice CloseGraph
DetectGraph DrawPoly Ellipse FillEllipse FillPoly
FloodFill GetArcCoords GetAspectRatio GetDefaultPalette
GetFillPattern GetFillSettings GetImage GetLineSettings
GetModeRange GetPalette GetTextSettings
GetViewSettings GraphDefaults InitGraph Line LineRel
LineTo MoveRel MoveTo OutText OutTextXY PieSlice PutImage
PutPixel Rectangle RestoreCrtMode Sector SetActivePage
SetAllPalette SetAspectRatio SetBkColor SetColor
SetFillPattern SetFillStyle SetGraphBufSize
SetGraphMode SetLineStyle SetPalette
SetRGBPalette SetTextJustify SetTextStyle
SetUserCharSize SetViewPort SetVisualPage
SetWriteMode GetBkColor() GetColor()
GetDriverName() GetGraphMode() GetMaxColor()
GetMaxMode() GetMaxX() GetMaxY() GetModeName()
GetPaletteSize() GetPixel() GetX() GetY()
GraphErrorMsg() GraphResult() ImageSize()
InstallUserDriver() RegisterBGIdriver() RegisterBGIfont()
TextHeight() TextWidth()
- Speaker
Sound
- Process-Handling
Execute Keep SwapVectors DosExitCode()
- Environment-Handling
EnvCount() EnvStr() GetEnv()
- Miscellaneous
Randomize Hi() Lo() ParamCount() ParamStr()
Random() SizeOf()
DosVersion() GetCBreak() SetCBreak()
GetVerify() SetVerify()
Delay
. 5.4 List of Procedures by Name order
Append(var f:text) - appends existing file
Arc(x,y:integer;angle1,angle2,,radius:word) - draw a circle arc
Assign(var f;name:string) - assigns file name to file variable
AssignCrt(var f:text) - associates a text file with the CRT
Bar(x1,y1,x2,y2:integer) - draws a bar
Bar3D(x1,y1,x2,y2:integer;Depth:Word;Top:Bollean) - draws 3-D bar
BlockRead(var f:file;var buf;count:word [;var result:Word]) - reads block
BlockWrite(var f:file;var buf;count:word [;var result:Word]) - write block
ChDir(path:string) - changes the current directory
Circle(x,y:integer;radius:integer) - draws circle
ClearDevice - clears graphics screen
ClearViewPort - clears current viewport
Close(var f) - closes an open file
CloseGraph - closes graphics system
ClrEol - clears cursor to end of line
ClrScr - clears the screen
Dec(var x [;n:longint]) - decrements a variable
Delay(ms:integer) - delays a specified number of milliseconds
Delete(var s:string;index:integer;count:integer) - deletes a substring
DelLine - deletes the line
DetectGraph(var GraphDriver, GraphMode:integer) - get graphic mode & driver
Dispose(var p:pointer) - disposes a dynamically allocated variable
DrawPoly(NumPoints:word; var PolyPoints) - draws a polygon
Ellipse(X,Y:integer;StAngle,EndAngle:word;XRadius,YRadius:word) - draws arc
Erase(var f) - erase a file
Exec(path, CmdLine:string) - executes a program
Exit - exits from current block
FillChar(var x; count:word; ch:value) - fills a specified value to memory
FillEllipseX,Y:integer;XRadius,YRadius:word) - draws an ellipse
FillPoly(Numpoints:word;var PolyPoints) - draws & fills a polygon
FindFirst(Path:string;Attr:word; var S:SearchRec) - find first dir match
FindNext(var S:SearchRec) - find the next entry that matches
FloodFill(X,Y:integer;Border:word) - fills a enclosed area with pattern
Flush(var f:text) - flushes the output buffer
Freemem(var p:pointer;size:word) - disposes a sized dynamic variable
FSplit(Path:PathStr;var Dir:DirStr;var Name:NameStr;Var Ext:ExtStr) - split
file name into strings of pathname,drive,name,extension
GetArcCoords(var ArcCoords:ArcCoordType) - get coordinates of Arc
GetAspectRatio(var Xasp,Yasp:word) - get aspect ratio of graphics screen
GetCBreak(var Break:Boolean) - get state of Ctrl-Break checking
GetDate(var Year,Month,Day,DayofWeek:word) - get system date
GetDir(d:byte; var s:string) - get current directory of specified drive
GetFAttr(var f;var Attr:word) - get attributes of a file
GetFillPattern(var FillPattern:FillPatternType) - get last fill pattern
GetFillSettings(var FillInfo:FillPatternType) - get last fill pattern,color
GetFTime(var f;var Time:longint) - get date,time of a file last updated
GetImage(x1,y1,x2,y2:integer; var BitMap) - save bit image of a region
GetIntVec(IntNo:byte;var Vector:pointer) - get address of a interrupt vector
GetLineSettings(var LineInfo:LineSettingsType) - get line style,pattern
GetMem(var p:pointer;size:word) - create new dynamic variable in size
GetModeRange(GraphDriver:integer;var LoMode,HiMode:integer) - get the
lowest and highest valid graphics mode for a given driver
GetPalette(var Palette:PaletteType) - get current palette and its size
GetTextSettings(var TextInfo:TextSettingsType) - get font,size & direction
GetTime(var Hour,Minute,Second,Sec100:word) - get system time
GetVerify(var Verify:Boolean) - get state of verify flag of DOS disk write
GetViewSettings(var ViewPort:ViewPortType) - get viewport & clip settings
GotoXY(X,Y:byte) - move cursor to X column, Y row
GraphDefault - reset graphics system of viewport,palette,colors,line,etc
Halt[(exitcode:word)] - halt the execution and return to DOS
HighVideo - turn intensity on
Inc(var x [;n:longint] - increment a variable
InitGraph(var GraphDriver:integer;var GraphMode:integer;DriverPath:string) -
select graphics mode and initialize graphics system
Insert(source:string;var s:string;index:integer) - inset a substring
InsLine - insert a line
Intr(intNo:byte;var Regs:Registers) - do software intrrupt
Keep(ExitCode:word) - terminate but stay resident in memory
Line(x1,y1,x2,y2:integer) - draw a line
LineRel(Dx,Dy:integer) - draw a line to a point relative to current pointer
LineTo(X,Y:integer) - draw a line from current pointer
LowVideo - turn off intensity
Mark(var p:pointer) - store the pointer variable for RELEASE procedure
MkDir(path:string) - create a subdirectory
Move(var source,dest;count:word) - copy contiguous bytes
MoveRel(Dx,Dy:integer) - move the current pointer a relative distance
MoveTo(X,Y:integer) - move the current pointer to new position
MsDos(var Regs:Registers) - do a DOS function interrupt
New(var p:pointer) - dynamic allocate a variable and set pointer
NormVideo - restore the text attribute to program startup state
NoSound - turn off speaker
OutText(TextString:string) - output text string at current pointer
OutTextXY(X,Y:integer;TextString:string) - output text at XY position
OvrClearBuf - clear the overlay buffer
OvrInit(FileName:string) - initialize the overlay manager and overlay file
OvrInitEMS - load the overlay file into EMS
OvrSetBuf(BufSize:longint) - set the size of the overlay buffer
PackTime(var DT:DateTime; var Time:longint) - pack DateTime record to 4 byte
PieSlice(x,y:integer;StAngle,EndAngle,Radius:word) - draw and file pie slice
PutImage(x,y:integer;var BitMap;BitBit:word) - put a bit image onto screen
PutPixel(x,y:integer;Pixel:word) - plot a pixel
Randomize - initialize a random value
Read([var f:text;] v1 [,v2,...,vn]) - read data from text file to variables
Read(f,v1 [,v2,...,vn]) - read a file component into a variable
Readln([var f:text;] v1 [,v2,...,vn]) - read text data and skip to next line
Rectangle(x1,y1,x2,y2:integer) - draw rectangle
Release(var p:pointer) - dispose all dynamically allocated variables
Rename(var f;newname:string) - rename a file
Reset(var f [:file; recsize:word]) - open an existing file
RestoreCrtMode - restore screen mode to prior state
Rewrite(var f [:file;recsize:word]) - create and open a new file
RmDir(path:string) - remove an empty subdirectory
RunError([ErrorCode:word]) - stop the program and generate a run-time error
Sector(x,y:integer;StAngle,EndAngle,XRadius,YRadius:word) - draw an sector
Seek(var f; n:longint) - move the current file postion
SetActivePage(Page:word) - set the active page for graphics
SetAllPalette(var Palette) - change all palette colors
SetAspectRatio(Xasp,Yasp:word) - change the aspect ratio
SetBkColor(Color:word) - set background color
SetCBreak(Break:Boolean) - set Ctrl-Break checking on
SetColor(Color:word) - set the current drawing color
SetDate(Year,Month,Day:word) - set system date
SetFAttr(var f;Attr:word) - set the attributes of a file
SetFillPattern(Pattern:FillPatternType;Color:word) - select a fill pattern
SetFillStyle(Pattern:word;Color:word) - set fill pattern and color
SetFtime(var f;Time:longint) - reset the date and time of a file
SetGraphBufSize(BufSize:word) - set the buffer size for scan and flood fill
SetGraphMode(Mode:integer) - set system to graphics mode
SetIntVec(IntNo:byte;Vector:pointer) - set a interrupt vector to new address
SetLineStyle(LineStyle:word;Pattern:word;Thickness:word) - set line style
SetPalette(ColorNum:word;Color:shortint) - set palette color
SetRGBPalette(ColorNum,RedValue,GreenValue,BlueValue:integer) - modify
palette entries for IBM-8514 and VGA drivers
SetTextBuf(var f:text;var buf [;size:word]) - set an I/O buffer to text file
SetTextJustify(Horiz,Vert:word) - set text justification values
SetTextStyle(Font:word;Direction:word;CharSize:word) - set text style
SetTime(Hour,Minute,Second,Sec100:word) - set system time
SetUserCharSize(MultX,DivX,MultY,DivY:word) - set character size
SetVerify(Verify:Boolean) - set DOS verify flag
SetViewPort(x1,y1,x2,y2:integer;Clip:Boolean) - set output viewport
SetVisualPage(Page:word) - set visual graphics page number
SetWriteMode(WriteMode:integer) - set the writing mode for line drawing
Sound(Hz:word) - sound the speaker
Str(x [:width [:decimals]]; var s:string) - convert numeric to string
SwapVectors - swap the interrupt vector
TextBackground(color:byte) - select background color
TextColor(color:byte) - select foreground character color
TextMode(Mode:word) - select text mode
Truncate(var f) - truncate file at current file position
UnpackTime(Time:longint;var DT:DateTime) - unpack date-and-time record
Val(s:string,var v;var code:integer) - convert string to numeric format
Window(x1,y1,x2,y2:byte) - defines a text window
Write([var f:text;] v1 [,v2,...,vn]) - write values to a text file
Write(f, v1 [,v2,...,vn]) - write a variable to a file
Writeln([var f:text;] v1 [,v2,...,vn]) - write text file and CR/LF
. 5.5 List of Functions by Name
Abs(x):same type - get absolute value
Addr(x):pointer - get address of
ArcTan(x:real):real - get arctangent
Chr(x:byte):char - get character
Concat(string1,string2 [,stringN]:string):string - concatenate strings
Copy(s:string,index:integer,count:integer):string - get a substring
Cos(x:real):real - get cosine
CSeg:word - get CS register value
DiskFree(Drive:word):longint - get number of free bytes in a drive
DiskSize(Drive:word):longint - get total size in bytes in a drive
DosExitCode:word - get exit code of a subprocess
DosVersion:word - get DOS version number
DSeg::word - get DS register value
EnvCount:integer - get number of strings in DOS environment
EnvStr(Index:integer):string - get a specified environment string
Eof[(var f:text)]:Boolean - get the status of EOF condition in a text file
Eof(var f):Boolean - get the status of EOF condition in a file
Eoln[(var f:text)]:Boolean - get the status of EOL of a file
Exp(x:real):real - get the exponential of a value
FExpand(Path:PathStr):PathStr - expand a file name to a file specification
FilePos(var f):longint - get the file position of a file
FileSize(var f):longint - get the file size
Frac(x:real):real - get the fractional part of a real value
Fsearch(Path:PathStr;DirList:string):PathStr - search a file in a given PATH
GetBkColor:word - get the index value of the current background color
GetColor:word - get the color value
GetDefaultPalette(var Pal:PaletteType):PaletteType - get palette definition
GetDriveName:string - get the name of the current driver
GetEnv(EnvVar:string):string - get the value of a specified environment var.
GetGraphMode:integer - get the current graphics mode
GetMaxColor:word - get the highest color value for SetColor procedure
GetMaxMode:word - get the maximum mode number for the current driver
GetMaxY:integer - get the x resolution of the current graphics driver & mode
GetMaxY:integer - get the y resolution of the current graphics driver & mode
GetModeName(ModeNumber:word):string - get the name of the graphics mode
GetPaletteSize:word - get the size of the paletter color entries
GetPixel(X.Y:integer):word - get the pixel value
GetX:integer - get the X coordinate of the current position
GetY:integer - get the Y coordinate of the current position
GraphErrorMsg(ErrorCode:integer):string - get the string of error message
GraphResult:integer - get the error code
Hi(x):byte - get the high-order byte
ImageSize(x1,y1,x2.y2:integer):word - get the number of bytes required to
store a rectangular region of the screen
InstallUserDriver(Name:string;AutoDetectPtr:pointer):word - install driver
InstallUserFont(FontFileName:string):integer - install a new font to BGI
Int(x:real):real - get integer part of real
IOresult:word - get integer status of last I/O operation
KeyPressed:Boolean - check if key has been pressed
Length(s:string):integer - get length of a string
Ln(x:real):real - get natural logarithm
Lo(x):byte - get low-order byte
MaxAvail:longint - get the largest available contiguous free block of memory
MemAvail:longint - get the sum of all available free memory in heap
Odd(x:longint):Boolean - check if x is an odd number
Ofs(x):word - get the offset address
Ord(x):longint - get the ordinal number
OvrGetBuf:longint - get the current size of the overlay buffer
ParamCount:word - get the number of parameters passed to the program
ParamStr(index):string - get the string of specified command line parameter
Pi:real - get the value of Pi
Pos(substr,s:string):byte - get the position of a substring
Pred(x):same type as x - get the predecessor of the x
Ptr(seg,ofs:word):pointer - get the pointer value
Random[(range:word)]:real/word - get a random number
ReadKey:char - read a character
RegisterBGIdriver(driver:pointer):integer - load a driver file and record it
RegisterBGIfont(font:pointer):integer - load a BGI font and record it
Round(x:real)::longint - round a real number to an integer
SeekEof[(var f:text)]:Boolean - get the EOF status of a text file
SeekEoln[(var f:text)]:Boolean - get the EOL status of a text file
Seg(x):word - get the segment address
Sin(x:real):real - get the sine of x
SizeOf(x):word - get the number of bytes used by x
SPtr:word - get the value of SP register
Sqr(x):same type as x - get square of x
Sqrt((x:real):real - get square root
Sseg:word - get the value of SS register
Succ(x):same type as x - get the successor of x
Swap(x):same type as x - swap the high-order byte with low-order byte
TextHeight(TextString:string):word - get the height of a string in pixels
TextWidth(TextString:string):word - get the width of a string in pixels
Trunc(x:real):longint - truncate a real value to integer
UpCase(ch:char):char - convert a character from lower case to upper case
WhereX:byte - get X-coordinate of current cursor position
WhereY:byte - get Y-coordinate of current cursor position
. 6. Program Structure
Program Heading
- start with key word 'PROGRAM'
- followed by program name and a semicolon(;)
- example : PROGRAM myprogram;
Declaration Part
- Label declaration part
-- head with word 'LABEL' followed by a list of label identifiers
separated by commas and terminated by semi-colon
-- example :LABEL EXIT,LOOP1;
- Constant definition part
-- head with word 'CONST' followed by a list of constant
assignments separated by semi-colon
-- each assignment consists of an identifier followed by an equal
sign and a constant
-- example : CONSTANT MAX_ROW = 25;
- type definition part
-- head with word 'TYPE' followed by a list of type assignment
separated by semi-colon
-- each assignment consists of an identifier followed by an equal
sign and a type
-- example : TYPE DAY = (MON,TUE,WED,THUR,FRI,SAT,SUN);
- variabel decalration part
-- head with word 'VAR' followed by a list of identifiers
separated by comma, each followed by a colon and a type
-- the scope of this variable is the block in which it is defined
-- example : VAR X1,Y1,X2,Y2:INTEGER;
- procedure declaration part
-- consist of procedure heading and a block which consist of a
declaration part and a statement part
-- procedure heading headed with word 'PROCEDURE' followed by an
identifier (procedure name) followed by a formal parameter list
-- example : PROCEDURE SWAP (VAR X,Y:INTEGER);
- function declaration part
-- same as procedure declaration part, except headed with word
'FUNCTION' and the heading must defined the type of the
function return. The return is defined by adding a colon
and a type
-- example : FUNCTION FACTOR(X:INTEGER):INTEGER;
Statement Part
- start with key word 'BEGIN' and terminate with key word 'END' and '.'
. 7.1 Sample of Main Program
program Sample1;
begin
writeln('Welcome to TURBO Pascal programming with kEDITOR');
end.
. 7.2 Sample of Main Program calling a Sub-program
program Sample2;
var i:integer;
procedure subpgm1(var i:integer);
begin
i := 1;
end;
begin
subpgm1(i);
writeln('The value of I is :',i);
end.
. 7.3 Sample of Main Program calling a Function
program sample3;
type string80 = STRING[80];
function UpString (Strg : String80 ) : String80;
var i : integer;
begin
for i := 1 to length(strg) do
strg[i] := UpCase(strg[i]);
UpString := strg;
end;
begin
writeln(UpString('Hello the world'));
end.
. 7.4 Sample of WHILE...DO statement
while (not EOF(input_file) do
begin
...
end;
. 7.5 Sample of REPEAT...UNTIL statement
if (IOresult = 0) then
begin
file_exit=TRUE;
close(in_file);
end
else
file_exit=FALSE;
. 7.6 Sample of FOR...DO statement
for i := 1 to 5 do
for j := 1 to 10 do
begin
arrayX [i,j] = i + j;
arrayY [i,j] = i - j;
end;
. 7.7 Sample of IF...THEN...ELSE statement
if x < 0 then
writeln('x is negative')
else if x = 0 then
writeln('x is zero')
else writeln('x is positive');
. 7.8 Sample of CASE...OF statement
case choice of
'A','a' : writeln('Option A selected');
'B','b' : writeln('Option B selected');
'C','c' : writeln('Option C selected');
end; {case}
. 7.9 Sample of GOTO statement
program Sample9;
label loop, exit;
const ESC = #27;
var choice : char;
if (choice = ESC) then
goto exit;
else goto loop;
exit: writeln('End of Program');
end.
. 7.10 Sample of Menu Displaying and Choice Selecting
program Sample10;
uses crt;
label quit;
Const
ESC = #27;
var char1, attr : char;
begin
clrscr;
writeln;
writeln('A : Add a book to booklist');
writeln('B : Update information to booklist');
writeln('C : Delete a book from the booklist');
writeln('D : Quit');
writeln;
write('Enter your choice ? ');
attr := ReadKey;
if (attr = ESC) then goto Quit;
Quit: writeln('End of Program');
end.
. 7.11 Sample of Sequential File Input (Read)
program sample11;
uses crt;
type book_type = record
title : string[20];
cost : integer;
end;
var book_data : book_type;
book_file : file of book_type;
begin
clrscr;
assign(book_file,'BOOKLIST.DAT');
reset(book_file);
while not eof(book_file) do
begin
read(book_file,book_data);
writeln('Book Title : ',book_data.title);
writeln('Book Cost : ',book_data.cost);
end;
close(book_file);
end.
. 7.12 Sample of Sequential File Output (Write)
program sample12;
uses crt;
type book_type = record
title : string[20];
cost : integer;
end;
var book_data : book_type;
book_file : file of book_type;
begin
assign(book_file,'BOOKLIST.DAT');
rewrite(book_file);
repeat
clrscr;
writeln('Book Title : ');
readln(book_data.title);
writeln('Book Cost : ');
readln(book_data.cost);
until (book_data.title='');
close(book_file);
end.
. 7.13 Sample of Text File Input (Write)
program sample13;
uses crt;
const ENTER = #13;
LF = #10;
var text_file : text;
achar : char;
begin
writeln('Enter text line up to 80 characters long. Ctrl-Z to end');
assign(text_file,'PASCAL.SRC');
rewrite(text_file);
repeat
achar := ReadKey;
if (achar = ^M) then
writeln;
if (achar <> ^Z) then
write(achar);
write(text_file,achar);
until (achar = ^Z);
close(text_file);
end.
. 7.14 Sample of Text File Output (Read)
program sample14;
const ENTER = #13;
LF = #10;
var text_file : text;
text_line : string[80];
achar : char;
begin
assign(text_file,'PASCAL.SRC');
reset(text_file);
while not eof(text_file) do
begin
readln(text_file,text_line);
writeln(text_line);
end;
close(text_file);
end.
. 8. Compiler Directives
- Source code embedded form : {$option+} or {$opttion-}
{$option info-string}
- Command-line Reference form : TPC [/$opt1/$opt2.../$optn] FILENAME
- Switch Directive : Turn compiler features by specifying + or - after the
directive name. The following are the default
A+ Align words and typed constants for non-8088 CPU
B- Disable complete Boolean Evaluation
D+ Enable the generation of debug information
E+ Enable the linking with 8087 emulator
F- Disable using the FAR call for all procedures or functions calling
I+ Generate I/O error checking for each I/O operation
L+ Enable the generation of local symbol information
N- Do not generate the code to do real-time calculation by calling
run-time library routine
O- Disable overlay code generation
R- Disable the generation of range-checking code
S+ Enable the generation of stack-overflow checking code
V+ Perform type-checking on strings passed as variable parameters
- Parameter Directives :
-- Source code embedded form
I filename Include file
L filename Link with named file
M stacksize,heapmin,heapmax Specifies stack size,minimum and
maximum ofthe heap. Default is (16384,0,655360)
O unitname Make a unit into an overlay
-- Command-line Reference form : TPC FILENAME [/opta/optb.../opt?]
B Build
Ddefines Conditional Defines
E EXE & TPU Directory
Fseg:ofs Find Error
GS Segments Map File
GP Publics Map File
GD Detailed Map File
Ipath Include Directories
L Link Buffer
M Make
Opath Object Directories
Q Suppress printing names,line numbers during compilation
Tpath Turbo Directory
Upath Unit Directories
V Stand-alone Debugging
- Conditional Directives : only source code embedded form
{$DEFINE name}
{$UNDEF name}
{$IFDEF name}
{$IFNDEF name}
{$IFOPT switch}
{$ELSE}